#include "Collider.h"


Collider::Collider()
{
	m_x0 = m_y0 = m_xf = m_yf;
}

Collider::Collider(int x0, int y0, int xf, int yf)
{
	m_x0 = x0;
	m_y0 = y0;
	m_xf = xf;
	m_yf = yf;
	m_isRigid = true;
}

Collider::Collider(int x0, int y0, int xf, int yf, bool collisions)
{
	m_x0 = x0;
	m_y0 = y0;
	m_xf = xf;
	m_yf = yf;
	m_isRigid = collisions;
	m_type = STATIC;
}

Collider::Collider(int x0, int y0, int xf, int yf, bool collisions, Type type)
{
	m_x0 = x0;
	m_y0 = y0;
	m_xf = xf;
	m_yf = yf;
	m_isRigid = collisions;
	m_type = type;
}

Collider::~Collider()
{
}

int * Collider::GetCoordinates()
{
	return new int[4]{m_x0, m_y0, m_xf, m_yf};
}

bool Collider::Collides(Collider * other)
{
	if (!m_isRigid || !other->IsRigid()) return false;
	int * otherCoordinates = other->GetCoordinates();
	if (((m_x0 >= otherCoordinates[0] && m_x0 <= otherCoordinates[2]) || (m_xf >= otherCoordinates[0] && m_xf <= otherCoordinates[2])) || ((m_x0 <= otherCoordinates[0] && otherCoordinates[0] <= m_xf) || (m_xf >= otherCoordinates[2] && otherCoordinates[2] >= m_x0)))
	{
		if (((m_y0 >= otherCoordinates[1] && m_y0 <= otherCoordinates[3]) || (m_yf >= otherCoordinates[1] && m_yf <= otherCoordinates[3])) || ((m_y0 <= otherCoordinates[1] && otherCoordinates[1] <= m_yf) || (m_yf >= otherCoordinates[3] && otherCoordinates[3] >= m_y0)))
		{
			delete(otherCoordinates);
			return true;
		}
		else
		{
			delete(otherCoordinates);
			return false;
		}
	}	
	else
	{
		delete(otherCoordinates);
		return false;
	}
}

void Collider::SetCoordinates(int x0, int y0, int xf, int yf)
{
	m_x0 = x0;
	m_y0 = y0;
	m_xf = xf;
	m_yf = yf;
}

bool Collider::IsRigid()
{
	return m_isRigid;
}

void Collider::SetCollisions(bool collides)
{
	m_isRigid = collides;
}

void Collider::SetType(Type type)
{
	m_type = type;
}

Collider::Type Collider::GetType()
{
	return m_type;
}